document.write('<script src="../js/globalDatas.js"></script>');

//检测本地是否有指定文件 downloads
function isHavefile(FTPfilename, basefilepath, callBack,filename) {
	var descBasefilepath = "_" + basefilepath + "/";
	plus.io.resolveLocalFileSystemURL(descBasefilepath, function(entry) {
		var dirReader = entry.createReader();
		dirReader.readEntries(function(entries) {
			entries.sort(sortCompareEntry);
			var currentEntry = 0;
			var finalFileName = FTPfilename;
			for(var i = 0; i < entries.length; i++) {
				var oneEntry = entries[i];
				if(oneEntry.name == FTPfilename || oneEntry.name == filename) {
					currentEntry = 1;
					if (oneEntry.name == filename) {
						finalFileName = filename;
					}
					break;
				}
			}
			if(currentEntry == 0) { //本地没有文件时
				callBack("none");
			} else {
				var data = getfilepath(finalFileName,basefilepath);
				callBack(data);
			}
		}, function(e) {
			callBack("error");
			console.log("打开目录失败");
		});
	}, function(e) {
		callBack('error');
		console.log("打开目录失败");
	});
}

function sortCompareEntry(a, b) {
	if(a.isDirectory && b.isFile) {
		return -1;
	} else if(a.isFile && b.isDirectory) {
		return 1;
	} else {
		return a.name - b.name;
	}
}

//获取文件路径
function getfilepath(filename, basefilepath) {
	var descBasefilepath = "_" + basefilepath + "/";
	var data = "";
	if(plus.os.name == "Android") {
		data = plus.io.convertLocalFileSystemURL(descBasefilepath);
		data += filename;
	} else {
		if(debugStatus) {
			data = "../../../../../../Library/Caches/Pandora/" + basefilepath + "/" + filename;
		} else {
			var str = plus.io.convertLocalFileSystemURL("_www/");
			var str2 = plus.io.convertLocalFileSystemURL(descBasefilepath)
			var rodeArr = str.split("/");
			var pdfrode = "..";
			for(var i = 0; i < rodeArr.length; i++) {
				if(rodeArr[i].length != 0) {
					pdfrode = pdfrode + "/..";
				}
			}
			pdfrode += str2;
			data = pdfrode + "/" + filename;
		}
	}
	return data;
}

//检测本地文件数量
function getfileCount(filetype, basefilepath, callBack) {
	var descBasefilepath = "_" + basefilepath + "/";
	plus.io.resolveLocalFileSystemURL(descBasefilepath, function(entry) {
		var dirReader = entry.createReader();
		dirReader.readEntries(function(entries) {
			entries.sort(sortCompareEntry);
			var currentEntry = 0;
			for(var i = 0; i < entries.length; i++) {
				var oneEntry = entries[i];
				if(oneEntry.name.indexOf(filetype) != -1) {
					currentEntry += 1;
				}
			}
			callBack(currentEntry);
		}, function(e) {
			callBack("error");
			console.log("打开目录失败");
		});
	}, function(e) {
		callBack('error');
		console.log("打开目录失败");
	});
}
/*
 * 对比两个路径
 */
function compareTowRode() {
	var str1 = plus.io.convertLocalFileSystemURL("_www/");
	var str2 = plus.io.convertLocalFileSystemURL("_downloads/");
	var divitem = document.getElementById("dataDiv");
	divitem.innerText = "_www:" + str1 + "\n_downloads:" + str2;
}